
var local="http://47.104.10.151";
var bool_user_Email=true;
var bool_user_Mobile=true;
//

function fuck_login() {
  searchMobile();
  if(bool_user_Mobile==false){
    alert("手机号码不存在");
  }else {
    searshEmail();
    if(bool_user_Email==false){
      alert("邮箱不存在");
    }else {

      login();

    }
  }
  bool_user_Email=true;
  bool_user_Mobile=true;
}





function login() {
  function creatxmlHTTP1() {
    if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
      var xmlHttp=new XMLHttpRequest();
    }else {
      // IE6, IE5 浏览器执行代码
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    return xmlHttp;
  }
    var xmlHttp=creatxmlHTTP1();
    var url=local+":8080/login/loginUser";
    var txt="";//用于存储拼接字符串；
    //获取数据
    var email=document.getElementById("loginName").value;
    var password=document.getElementById("password").value;
    //拼接字符
    txt="email="+email+"&password="+password;
    xmlHttp.open("POST",url,true);
    xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlHttp.send(txt);

    xmlHttp.onreadystatechange=function() {
      if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var result = xmlHttp.responseText;
        var json = eval("(" + result + ")");
        if (json.msg != null) {
          alert("账号密码错误");
        }
        else {
          KeyId = json.data.keyId;


          alert("登入成功" + KeyId);

          clearCookie('userId');
          setCookie('userId', KeyId, 1);
          var UserId = getCookie('userId');
          var a = 1;
          var b = 2;
          var c = 3;
          var d = 4;

          if (json.data.keyId == a) {
            window.open('../超级管理员检索/main/StockMain.html');
          }
          else if (json.data.keyId == b) {
            window.open('../超级管理员检索/main/Bidmain.html');
          }
          else if (json.data.keyId == c) {
            window.open('../超级管理员检索/main/ResumeMain.html');
          }
          else if (json.data.keyId == d) {
            window.open('../超级管理员检索/main/UserMain.html');
          }
          else {
            window.open('../login_index.html');
          }
        }

      }
    }

}


function searshEmail() {
  function creatxmlHTTPforEmail() {
    if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
      var xmlHttp=new XMLHttpRequest();
    }else {
      // IE6, IE5 浏览器执行代码
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlHttp;
  }
  var email=document.getElementById("loginName").value;
  var xmlHttpForEmail=creatxmlHTTPforEmail();
  var url_Em="http://localhost:8080/login/searchEmail";
  var txt_Em= "email="+email;
  xmlHttpForEmail.open("POST",url_Em,true);
  xmlHttpForEmail.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xmlHttpForEmail.send(txt_Em);
  xmlHttpForEmail.onreadystatechange=function () {
    if (xmlHttpForEmail.readyState == 4 && xmlHttpForEmail.status == 200) {
    var result_Em=xmlHttpForEmail.responseText;
    var json_Em=eval("(" + result_Em + ")");
    var error='error';
    if(json_Em.msg==error){
      bool_user_Email=false;
    }

  }

}}



function searchMobile(){
    function creatxmlHTTP2() {
    if(window.XMLHttpRequest){
//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
      var xmlHttp=new XMLHttpRequest();
    }else {
      // IE6, IE5 浏览器执行代码
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return xmlHttp;
  }
    var xmlHttp1=creatxmlHTTP2();
    var email=document.getElementById("loginName").value;
    url1 = local+":8080/login/searchMobile";
    txt1 = "mobile=" + email;
    xmlHttp1.open("POST", url1, true);
    xmlHttp1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp1.send(txt1);
    xmlHttp1.onreadystatechange = function () {
        if (xmlHttp1.readyState == 4 && xmlHttp1.status == 200) {
            var result = xmlHttp1.responseText;
            var json = eval("(" + result + ")");
            var error = 'error';
            if (json.msg == error) {
              bool_user_Mobile=false;
            }

        }
    };



}



















//JS操作cookies方法!
//写cookies
function setCookie(c_name,value,expiredays)
{
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" +escape(value)+
        ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+";path=/";
}
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=")
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return ""
}
function clearCookie(name) {
    setCookie(name, "", -1);
}